package com.ruoyi.system.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.InvoiceRecordsAudit;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 中心库月结审计Mapper接口
 * 
 * @author ruoyi
 * @date 2024-06-28
 */
public interface InvoiceRecordsAuditMapper 
{
    /**
     * 查询中心库月结审计
     * 
     * @param id 中心库月结审计主键
     * @return 中心库月结审计
     */
    public InvoiceRecordsAudit selectInvoiceRecordsAuditById(Long id);

    /**
     * 查询中心库月结审计列表
     * 
     * @param invoiceRecordsAudit 中心库月结审计
     * @return 中心库月结审计集合
     */
    public List<InvoiceRecordsAudit> selectInvoiceRecordsAuditList(InvoiceRecordsAudit invoiceRecordsAudit);

    /**
     * 新增中心库月结审计
     * 
     * @param invoiceRecordsAudit 中心库月结审计
     * @return 结果
     */
    public int insertInvoiceRecordsAudit(InvoiceRecordsAudit invoiceRecordsAudit);

    /**
     * 修改中心库月结审计
     * 
     * @param invoiceRecordsAudit 中心库月结审计
     * @return 结果
     */
    public int updateInvoiceRecordsAudit(InvoiceRecordsAudit invoiceRecordsAudit);

    /**
     * 删除中心库月结审计
     * 
     * @param id 中心库月结审计主键
     * @return 结果
     */
    public int deleteInvoiceRecordsAuditById(Long id);

    /**
     * 批量删除中心库月结审计
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteInvoiceRecordsAuditByIds(Long[] ids);


    @Select("<script>" +
            "select r.product_code,r.model,specs,r.product_price,r.plarn_price,r.product_price*sum(r.product_count)plarn_money, sum(r.plarn_price*r.product_count)price_money,sum(r.product_count)count,r.settlement_mode," +
            "r.product_name,r.product_brand,r.provide,r.company,r.status,g.product_group,r.create_time  from invoice_records_audit r left join invoice_group g on r.product_code = g.product_code where 1=1 " +
            "<if test=\"productName!=null and productName!= ''\">" +
            " and r.product_name = #{productName} " +
            "</if>" +
            "<if test=\"provide!=null and provide!= ''\">" +
            " and r.provide = #{provide} " +
            "</if>" +
            "<if test=\"company!=null and company!= ''\">" +
            " and r.company = #{company} " +
            "</if>" +
            "<if test=\"status!=null and status!= ''\">" +
            " and r.status = #{status} " +
            "</if>" +
            "<if test=\"startTime!=null and startTime!= ''\">" +
            " and r.create_time = #{startTime} " +
            "</if>" +
            "<if test=\"productGroup!=null and productGroup!= ''\">" +
            " and g.product_group is NULL " +
            "</if>" +
            " group by r.product_code,r.model,r.specs,r.product_price,r.settlement_mode,r.product_name,r.product_brand,r.provide,r.plarn_price,r.company,r.status,g.product_group,date_format(r.create_time,'%Y-%m')" +
            " order by g.product_group" +
            "</script>")
    public List<Map<String,Object>>  listWebInfo(@Param("productName")String productName,
                                                 @Param("provide")String provide,
                                                 @Param("company")String company,
                                                 @Param("status")String status, @Param("productGroup")String productGroup, @Param("startTime")String startTime);

    @Select("<script>" +
            "select sum(product_money)allMoney from invoice_records_audit where 1=1 " +
            "<if test=\"provide!=null and provide!= ''\">" +
            " and provide = #{provide} " +
            "</if>" +
            "<if test=\"startTime!=null and startTime!= ''\">" +
            " and create_time = #{startTime} " +
            "</if>" +
            "</script>")
    public Double  selectAllMoney(@Param("provide")String provide,@Param("startTime")String startTime);

    @Select("<script>" +
            "select sum(product_count*product_price)sumMoney from invoice_records_audit where 1=1 " +
            "<if test=\"provide!=null and provide!= ''\">" +
            " and provide = #{provide} " +
            "</if>" +
            "<if test=\"startTime!=null and startTime!= ''\">" +
            " and create_time = #{startTime} " +
            "</if>" +
            "</script>")
    public Double  selectSumProductMoney(@Param("provide")String provide,@Param("startTime")String startTime);

    @Select("delete from invoice_records_audit where create_time = #{time}")
    public Integer deleteUpload(@Param("time")String time);

}
